package com.example.campustalent.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.campustalent.R
import com.example.campustalent.adapter.MyContentAdapter
import com.example.campustalent.bean.ContentBean
import com.example.campustalent.databinding.ActivityMyContentBinding
import com.example.campustalent.databinding.ActivityRegisterBinding
import com.example.campustalent.utils.DbUtils
import com.example.campustalent.utils.SharedPreferencesUtils

class MyContentActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMyContentBinding
    private lateinit var mAdapter: MyContentAdapter
    private lateinit var preferencesUtils: SharedPreferencesUtils
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (DbUtils.liteOrm == null) {
            DbUtils.createDb(this, "CampusTalent")
        }
        preferencesUtils = SharedPreferencesUtils(this)
        binding = ActivityMyContentBinding.inflate(layoutInflater)
        val rootView: View = binding.root
        setContentView(rootView)
        binding.ivBack.setOnClickListener {
            finish()
        }
        mAdapter = MyContentAdapter()
        binding.recyclerView.apply {
            layoutManager = LinearLayoutManager(this@MyContentActivity)
            adapter = mAdapter
        }
        val list = DbUtils.getQueryByWhere(ContentBean::class.java, "name", arrayOf(preferencesUtils.getParam("name", "").toString()))
        if (list.isNullOrEmpty()){
            binding.tvTip.visibility = View.VISIBLE
            binding.recyclerView.visibility = View.GONE
        }else {
            binding.tvTip.visibility = View.GONE
            binding.recyclerView.visibility = View.VISIBLE
        }
        mAdapter.setNewData(list)
    }
}